<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="layout" content="main" />
        <g:set var="entityName" value="${message(code: 'solicitacao.label', default: 'Solicitacao')}" />
        <title><g:message code="default.list.label" args="[entityName]" /></title>
    </head>
    <body>
        <div class="body">
            <div class="cabelistlateral"><img src="${resource(dir:'images',file:'seta_cabecalho_20x20.png')}" /> Solicitações</div><br/>
            <g:if test="${flash.message}">
            <div class="message">${flash.message}</div>
            </g:if>
            <div class="list">
                <table>
                    <thead>
                        <tr>
                            <g:sortableColumn property="dtCadastro" title="${message(code: 'solicitacao.dtCadastro.label', default: 'Data Cadastro')}" />
                            <td>Estagiário</td>
                            <td>Unidade Concedente</td>
                            <th><g:message code="solicitacao.vaga.label" default="Vaga" /></th>
                            <g:sortableColumn property="situacao" title="${message(code: 'solicitacao.situacao.label', default: 'Situacao')}" />
                            <td>TCEs</td>
                            <td colspan="2" align="center">Ações</td>
                        </tr>
                    </thead>
                    <tbody>
                    <%
                    String situacao;
                    String style;
                    String cor;
                    String msg;
                    %>
                    <g:each in="${solicitacaoInstanceList}" status="i" var="solicitacaoInstance">
                        <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
                            <%
                            if(solicitacaoInstance.situacao == '0'){
                                situacao = "Aguardando";
                                style    = " style='color:#ff0000; font-weight:bold;'";
                            }else{
                                situacao = "Liberado";
                                style    = " style='color:#006600; font-weight:bold;'";
                            }
                            %>
                            <td><g:formatDate date="${solicitacaoInstance.dtCadastro}" format="dd-MM-yyyy" /></td>
                            <td>${solicitacaoInstance?.estagiario?.nome}</td>
                            <td>${solicitacaoInstance?.vaga?.unidadeConcedente?.nome}</td>
                            <td>
                              <img src="${resource(dir:'images',file:'ico_edit.png')}" alt="Visualizar Vaga" title="Visualizar Vaga" onclick="window.open('${createLink(controller:'vaga', action:'show', id:solicitacaoInstance.vaga.id)}');"/>
                                ${solicitacaoInstance?.vaga?.cargo}
                            </td>
                            <td<%=style%>>${situacao}</td>
                            <td class="numtces">
                                <%
                                cor = "concluido";
                                msg = "Concluído"
                                def tce = Tce.findAllBySolicitacao(solicitacaoInstance)
                                if(tce.size() > 0){
                                    for (int j=0; j<tce.size(); j++){
                                        if(tce.situacao[j] == "0"){
                                            cor = "aguardando";
                                            msg = "Aguardando geração do TCE"
                                        }
                                        if(tce.situacao[j] == "1" && tce.dtFim[j].after(new Date())){
                                            cor = "gerado";
                                            msg = "TCE gerado e/ou concluído"
                                        }
                                        if(tce.dtRescisao[j]){
                                            cor = "rescindido";
                                            msg = "Rescindido"
                                        }
                                        %>
                                        <a href="${createLink(controller:'tce', action:'show', id:tce.id[j])}" class="${cor}" title="TCE Nº ${j+1} - ${msg}">${j+1}</a>
                                        <%
                                    }
                                }
                                %>
                            </td>
                            <td class="btsalvarcadastro">
                                <g:if test="${!solicitacaoInstance.permiteCriarTce}">
                                    <input type="button" name="criar" value="CRIAR TCE" onclick="location.href='${createLink(controller:'tce', action:'create', id:solicitacaoInstance.id)}';"/>
                                </g:if>
                                <g:if test="${solicitacaoInstance.permiteRenovarTce}">
                                    <input type="button" name="criar" value="RENOVAR TCE" onclick="location.href='${createLink(controller:'tce', action:'create', id:solicitacaoInstance.id)}';"/>
                                </g:if>
                            </td>
                            <td class="ico">
                                <a href="${createLink(controller:'solicitacao', action:'excluirSolicitacao', id:solicitacaoInstance.id, params:[controlador:'solicitacao', acao:'list'])}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Confirma aexclusão do registro?')}');">
                                    <img src="${resource(dir:'images',file:'ico_delete.png')}" alt="Excluir" title="Excluir" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}"  />
                                </a>
                            </td>
                        </tr>
                    </g:each>
                    </tbody>
                </table>
            </div>
            <div class="paginateButtons">
                <g:paginate total="${solicitacaoInstanceTotal}" />
            </div>
        </div>
    </body>
</html>
